package classpath

import "os"
import "path/filepath"
import "strings"

func newWildcardEntry(path string) CompositeEntry {
	baseDir := path[:len(path)-1] // remove char *
	compositeEntry := []Entry{}
	walkFn := func(path string, info os.FileInfo, err error) error {
		if err != nil {
			return err
		}
		if info.IsDir() && path != baseDir {
			return filepath.SkipDir
		}
		if strings.HasSuffix(strings.ToLower(path), "jar") || strings.HasSuffix(strings.ToLower(path), "zip") {
			jarEntry := newZipEntry(path)
			compositeEntry = append(compositeEntry, jarEntry)
		}
		return nil
	}
	//走遍根目录下的文件树，为每个文件或者每个文件调用walkFn
	filepath.Walk(baseDir, walkFn)
	return compositeEntry
}
